﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HF
{
    internal static class ExceptionExt
    {
        public static void Throw(this Exception exception)
        {
            if (exception != null)
            {
                throw exception;
            }
        }

        public static T CheckArgumentNull<T>(this T souce, string paramName = null)
            where T : class
        {
            if (souce == null)
            {
                throw new ArgumentNullException(paramName);
            }
            return souce;
        }

        public static T? ParamNull<T>(this T? souce, string paramName = null, string msg = null)
            where T : struct
        {
            if (!souce.HasValue)
            {
                throw new ArgumentNullException(paramName, msg);
            }
            return souce;
        }

        public static void CheckArgumentOutOfRange(this bool condition, string paramName = null, string msg = null)
        {
            if (condition)
            {
                throw new ArgumentOutOfRangeException(paramName, msg);
            }
        }
    }
}
